import { defineComponent, reactive, ref } from "vue";
import Page from "@/components/public/page/page";
import { CardWithTitle } from "@/components/public/card/card";
import LTable from "@/components/public/lTable/lTable";
import { $cacheClear } from "@/api/systemConfiguration/systemConfiguration";
import { message } from "ant-design-vue";
import detailService from "@/modules/systemConfiguration/cacheManage/detail.service";
export default defineComponent({
  setup() {
    const state = reactive({
      toolbar: {
        left: ["refresh",],
        right: ["filter"],
      },
      dataSource: [],
      columns: [
        {
          title: "标签名称",
          dataIndex: "tagName",
          align: "center",
          width: "150px",
        },
        {
          title: "说明",
          dataIndex: "desc",
          align: "center",
          width: "200px",
        },
        {
          fixed: "right",
          title: "操作",
          dataIndex: "operation",
          align: "center",
          width: "160px",
        }
      ],
      loading: false,
    } as any);
    const LTableRef = ref(null as any);
    const $service = new detailService();
    return () => (
      <Page>
        <CardWithTitle title="数据缓存标签列表">
          <LTable
            ref={LTableRef}
            toolbar={state.toolbar}
            service={$service}
            v-model={state}
          >
            <a-table
              bordered={true}
              scroll={{ x: "max-content" }}
              dataSource={state.dataSource}
              columns={state.columns}
              loading={state.loading}
              v-slots={{
                bodyCell: ({ column, record }: any) => {
                  //操作
                  if (column.dataIndex === "operation") {
                    return (
                      <div class="operation">
                        <a-button
                          type="primary"
                          onClick={() => {
                            $cacheClear({ tagName: record.tagName }).then((res: any) => {
                              message.success('清除成功')
                            })
                          }}
                        >
                          清除
                        </a-button>
                      </div>
                    )
                  }
                },
              }}
            />
          </LTable>
        </CardWithTitle>
      </Page>
    )
  }
})